package com.hrpmar.controller;

import com.hrpmar.controller.dto.MessageSenderDto;
import com.hrpmar.pojo.MessageReply;
import com.hrpmar.service.MessageSenderService;
import com.hrpmar.utils.Pager;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by c on 2017-12-04.
 */
@RestController
@RequestMapping("/send")
public class MessageSenderRestController {

    @Resource
    private MessageSenderService messageSenderService;

    @RequestMapping("/search")
    public Pager search(Integer offset, Integer limit, MessageSenderDto condition, HttpServletRequest req){
        Pager pager = messageSenderService.search(offset,limit,condition,req);
        return pager;
    }

    @PostMapping("/huifu")
    public List<MessageReply> searchHuiFu(Integer mid){
        List<MessageReply> list = messageSenderService.searchHuiFu(mid);
        return list;
    }

    @PostMapping("/addHuiFu")
    public MessageReply addHuiFu(MessageReply messageReply,HttpServletRequest req){
        MessageReply messageReply1 = messageSenderService.addHuiFu(messageReply,req);
        return messageReply1;
    }

    @PostMapping("/updateIsReader")
    public String updateIsReader(Integer rid){
        String flag = "false";
        try{
            messageSenderService.updateIsReader(rid);
            flag="true";
        }catch (RuntimeException e){
            flag = "false";
        }
        return flag;
    }

}
